#include <cassert>
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> result, nums(nums1.begin(), nums1.end());
        for (int num : nums2) {
            if (nums.find(num) != nums.end()) {
                result.insert(num);
            }
        }
        return vector<int>(result.begin(), result.end());
    }
};

int main() {
    Solution s;

    vector<int> input1{1, 2, 2, 1}, input2{2, 2}, output1{2};
    vector<int> input3{4, 9, 5}, input4{9, 4, 9, 8, 4}, output2{4, 9};

    assert(s.intersection(input1, input2) == output1);
    assert(s.intersection(input3, input4) == output2);

    return 0;
}